
package com.monlyu.util;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * 日志操作
 * 
 * @author monlyu
 */
public class LogUtil {

    /**
     * 返回日志工厂实例,添加一个Exception
     * 
     * @since 2009-12-27
     */
    public static Log log(Class<? extends Object> clazz, Exception e){
        if (WebOptUtil.APP_ARGS.isDebug()) {
            System.out.println("------------以下为debug信息----------------");
            e.printStackTrace();
        }
        return LogFactory.getLog(clazz);
    }

    /**
     * 返回日志工厂实例
     * 
     * @since 2010-1-14
     */
    public static Log log(Class<? extends Object> clazz){
        return LogFactory.getLog(clazz);
    }

    /**
     * 输出日志@日期
     * 
     * @since 2009-12-28
     */
    public static void logWithDate(Class<?> cls, String msg, Exception e){
        LogUtil.log(cls, e).info(msg + "@" + DateUtil.now2Str());
        if (WebOptUtil.APP_ARGS.isDebug()) {
            e.printStackTrace();
        }
    }

    /**
     * 输出日志@时间
     * 
     * @since 2009-12-28
     */
    public static void logWithTime(Class<?> cls, String msg, Exception e){
        LogUtil.log(cls, e).info(msg + "@" + DateUtil.nowtime2Str());
        if (WebOptUtil.APP_ARGS.isDebug()) {
            e.printStackTrace();
        }
    }

    /**
     * 仅仅输出一个信息,当提示使用
     * 
     * @since 2010-1-14
     */
    public static void logWithTime(Class<?> cls, String msg){
        LogUtil.log(cls).info(msg + "@" + DateUtil.nowtime2Str());
    }

}
